<template>
    <view class="content">
        <view class="top">
            <view class="padding-lr-sm">
                <u-search placeholder="搜索内容" v-model="keyword" :show-action="false" height="70" @search="doSearch"></u-search>
            </view>
            <timeSearch @doSearch="doSearch" />
            
            <view class="nav">
                <view class="nav-i" :class="{active : type == 1}" @click="chooseNav(1)">待领取销售订单</view>
                <view class="nav-i" :class="{active : type == 2}" @click="chooseNav(2)">待领取退回订单</view>
                <view class="nav-i" :class="{active : type == 3}" @click="chooseNav(3)">已领取</view>
            </view>
        </view>
        
        <view class="box text-df" v-for="(item, index) in list" :key="index" 
            @click="$gTo(`/pages/sort/sort-details?id=${item.id}&type=${type}`)">
            <view class="item">
                <view class="item-l">订单号</view>
                <view class="item-r">{{ type == 3 ? item.belong : item.order_no }}</view>
            </view>
            <view class="item">
                <view class="item-l">下单时间</view>
                <view class="item-r">{{ type == 3 ? item.belong_time : item.create_time }}</view>
            </view>
            <view class="item">
                <view class="item-l" v-if="type == 2">供货单位</view>
                <view class="item-l" v-else>购货企业</view>
                <view class="item-r">{{item.shop}}</view>
            </view>
            <view class="box-down">
                <view>
                    <view class="item">
                        <view class="item-l" v-if="type == 2">销售人员</view>
                        <view class="item-l" v-else>采购人员</view>
                        <view class="item-r">{{item.buyer}}</view>
                    </view>
                    <view class="item">
                        <view class="item-l">是否冷链</view>
                        <view class="item-r">{{ item.is_freeze == 1 ? '是' : '否' }}</view>
                    </view>
                </view>
                <view class="neck-btn" v-if="type != 3">领单</view>
            </view>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
                type: 1,
                keyword: '',
                startTime: '',
                endTime: '',
            };
        },
        onShow() {
            this.list = []
            this.page = 1
            this.status = 'loadmore'
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            doSearch(data) {
                if (data) {
                    this.startTime = data.startTime
                    this.endTime = data.endTime
                }
                this.page = 1;
                this.list = [];
                this.status = 'loadmore';
                this.getList()
            },
            
            chooseNav(num) {
                if (this.type == num) return
                this.type = num
                this.list = []
                this.page = 1
                this.status = 'loadmore'
                this.getList()
            },
            
            getList() {
                let url = '', param = {}
                if (this.type == 3) {
                    // 已领取 待出库
                    url = 'inventory_out/out_list'
                    param = {
                        userToken: this.$getSync('userToken'),
                        page: this.page,
                        limit: 10,
                        keywords: this.keyword,
                        start_time: this.startTime,
                        end_time: this.endTime,
                    }
                } else {
                    // 待领取
                    url = 'inventory_out/unclaimed_list'
                    param = {
                        userToken: this.$getSync('userToken'),
                        page: this.page,
                        limit: 10,
                        keywords: this.keyword,
                        start_time: this.startTime,
                        end_time: this.endTime,
                        type: this.type, //1-订单  2-采购售后
                    }
                }
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax(url, param).then(ret => {
            		if (ret.status == 0) {
                        if (ret.data.length > 0) {
                        	this.list = this.list.concat(ret.data);
                        	this.page++;
                        	this.status = 'loadmore'
                        } else {
                        	this.status = 'nomore'
                        }
            		} else {
            			this.$toast(ret.message);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    
    page{
        background-color: #f5f5f5 !important;
    }
    .top{
        background-color: #fff;
    }
    .nav{
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .nav-i{
        width: calc(100vw / 3);
        font-size: 30rpx;
        font-weight: bold;
        text-align: center;
        padding-bottom: 30rpx;
    }
    .active{
        color: #ff4800;
        position: relative;
    }
    .active::after{
        display: block;
        content: '';
        width: 32rpx;
        height: 8rpx;
        background-color: #ff4800;
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
    }
    
    
    .box{
        background-color: #fff;
        border-radius: 15rpx;
        padding: 30rpx;
        margin: 25rpx 25rpx 0;
    }
    .item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 15rpx;
    }
    .item:last-child{
        padding-bottom: 0;
    }
    .item-l{
        width: 150rpx;
        color: #868686;
    }
    .item-r{
        flex: 1;
        word-break: break-all;
        white-space: pre-line;
    }
    .box-down{
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
    }
    .neck-btn{
        padding: 15rpx 50rpx;
        background-color: #0780f6;
        border-radius: 10rpx;
        color: #fff;
    }

</style>
